package controller;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;

@WebServlet("/search")
public class SearchController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String keyword=req.getParameter("keyword");
        String sortStr=req.getParameter("sort");
        if(sortStr==null || sortStr.equals("")){
            sortStr="0";
        }
        int sort=Integer.parseInt(sortStr);
//        System.out.println(keyword);
        if (keyword==null||keyword.isEmpty()){
            resp.sendRedirect("HomeController");
        }else{
            RequestDispatcher requestDispatcher=req.getRequestDispatcher("HomeController");
            requestDispatcher.forward(req, resp);
//            resp.sendRedirect("HomeController?sort="+sort+"&keyword="+ URLEncoder.encode(keyword,"UTF-8"));
        }
    }
}
